clear;clc;

%% Setup
% Information Structure
Info            =   struct('ParamList',{{'b_lb','B_Total_SS'}});
Info.ParamInput =   struct('XI',1/82.5/4,'Pir_SS',0.02/4,'KAPPA',0.00/4,...
                           'NU_C',1,'NU_L',1);
Info.Dim        =   length(Info.ParamList);

Info.StatName   =   {'Wealth-Income Ratio: Median',...'Median Wealth/Median Income','Prob. of Negative Wealth',...
                     'MPC: Median' ...,'Prob. of HtM','MPC: Average' ...
                     };
Info.Stat_Data  =   [0.35;0.15];

% Optimization 
ParaVec_0       =   [-1.0;0.4];               
lb              =   [-2.0;0.0];
ub              =   [0.0 ;4.0];

ObjFunction     =   @(Input)SubFun_Calibration_Eval(Info,Input);

%% Global Optimization
warning('off','all');

%--------------------------------------------------------------------------
% Particle Swarm
%--------------------------------------------------------------------------
rng default
options             =   optimoptions('particleswarm',...
                                     'Display','iter',...'SwarmSize',100.'HybridFcn',@fmincon,..
                                     'MaxTime',60*60*2,'UseParallel',true);
[ParamVec,fval,exitflag] ...
                    =   particleswarm(ObjFunction,length(lb),lb,ub,options);

[~,Result]          =   ObjFunction(ParamVec);

save('Calibration.mat','Info','Result','ParamVec');